package com.xsir.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xsir.common.Result;
import com.xsir.entity.Tag;
import com.xsir.service.ITagService;
import com.xsir.util.JwtUtil;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xsir
 * @since 2020-11-03
 */
@RestController
@RequestMapping("/tag")
public class TagController {
    @Resource
    private ITagService tagService;
    
    @GetMapping("/author")
    public Result author(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        Integer uid = (Integer) JwtUtil.decode(token).get("uid");
        List<Tag> tags = tagService.list(new QueryWrapper<Tag>().eq("user_id", uid));
        return Result.ok(tags);
    }
}
